<?php

class search extends a_admin_controller {

    protected $srv;
    
    public function __construct() {
        parent::__construct(FALSE);
        $this->load->library("json");
//        $this->srv = new service_l_product();
    }

    public function batch_assign() {
    }

    public function index()
    {
    }

    public function table()
    {
        $data=array();
        $start_index = $_POST['iDisplayStart'];
        $num_records = $_POST['iDisplayLength'];
        $sort_column = $_POST['iSortCol_0'];
        $sort_dir = $_POST['sSortDir_0'];
        $search_filter = $_POST['sSearch'];

        if($this->input->post('reset'))
           $this->destroy_user_search_session();
        else{
            $srv = new search_processor_l_product(trim($this->input->post("prod_name")), trim($this->input->post("upc")));

            $product_count = $srv->count_products();
            $products_found = $srv->list_product($start_index,
                                                $num_records, $sort_column, $sort_dir, $search_filter);
            $data['aaData'] = $products_found;
            $data['iTotalRecords'] = $product_count;
            $data['iTotalDisplayRecords'] = $product_count;
            $data['dir'] = 'asc';

        }

        echo $this->json->encode($data);
        die();
    }
}
